<?php

class Mem {

    private static $Memcache;

    private static function getMemcache() {
        if (!self::$Memcache) {
            self::$Memcache = new Memcache;
            self::$Memcache->pconnect('127.0.0.1', 11211, 1);
        }
        return self::$Memcache;
    }

    public static function getFromMem($key) {
        $mem = self::getMemcache();
        if ($mem) {
            return $mem->get($key);
        } else {
            return null;
        }
    }

    public static function setToMem($key, $value, $expire = 0) {

        $mem = self::getMemcache();
        if ($mem) {
            $mem->set($key, $value, 0, $expire);
        } else {
            return null;
        }
    }

    public static function delete($key) {
        $mem = self::getMemcache();
        if ($mem) {
            $mem->delete($key);
        } else {
            return null;
        }
    }

}

?>